home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- *
- * $Source: /unixb/home/unixlib/source/unixlib37/src/unix/c/RCS/gethostnam,v $
- * $Date: 1996/10/30 21:59:01 $
- * $Revision: 1.2 $
- * $State: Rel $
- * $Author: unixlib $
- *
- * $Log: gethostnam,v $
- * Revision 1.2 1996/10/30 21:59:01 unixlib
- * Massive changes made by Nick Burret and Peter Burwood.
- *
- * Revision 1.1 1996/04/19 21:35:27 simon
- * Initial revision
- *
- ***************************************************************************/
-
- static const char rcs_id[] = "$Id: gethostnam,v 1.2 1996/10/30 21:59:01 unixlib Rel $";
-
- #include <string.h>
- #include <errno.h>
- #include <unistd.h>
- #include <sys/os.h>
-
- /* gethostname() returns "acorn<station>" */
-
- int
- gethostname (char *name, size_t len)
- {
- int r[3];
- _kernel_oserror *e;
- static char buf[8];
- static char hex[16] =
- {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
- 'A', 'B', 'C', 'D', 'E', 'F'};
-
- /* Create a string that consists of "acorn<econet station number>". */
- strcpy (buf, "acorn");
- if (e = os_byte (0xa1, 0, 0, r))
- {
- __seterr (e);
- return -1;
- }
- buf[7] = 0;
- buf[6] = hex[r[1] & 0xf];
- buf[5] = hex[(r[1] >> 4) & 0xf];
-
- if (strlen (buf) <= len)
- {
- strcpy (name, buf);
- return 0;
- }
-
- errno = ENAMETOOLONG;
- strncpy (name, buf, len);
- buf[len] = '\0';
- return -1;
- }
-
- /* Set the name of the host machine. */
-
- int
- sethostname (const char *name, size_t length)
- {
- /* Bit of a difficult one to set under RISC OS. Set errno
- and return -1 which indicates that the calling process
- is not privileged enough to set the host name. */
- name = name;
- length = length;
- errno = EPERM;
- return -1;
- }
-